﻿using System.IO;
namespace Spider.Lib
{
    public class IOHelper
    {
        public static void Write(string content, string path)
        {
            //if not exists is create
            FileInfo file = new FileInfo(path);
            if (!file.Directory.Exists)
                file.Directory.Create();

            FileStream fs = new FileStream(path, FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            //开始写入
            sw.Write(content);
            //清空缓冲区
            sw.Flush();
            //关闭流
            sw.Close();
            fs.Close();
        }
        public static string Read(string path)
        {
            string retVal = string.Empty;
            FileStream fs = new FileStream(path, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);
            retVal = sr.ReadToEnd();
            fs.Close();
            sr.Close();
           
            return retVal;


        }
    }
}
